package com.zhao.wechat.rest;

import com.zhao.wechat.domain.UserInfo;
import com.zhao.wechat.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户信息管理视图层
 */
@RestController
@RequestMapping("/userInfo")
@Api(tags = "用户信息管理")
public class UserInfoRest {

	@Autowired
	private UserInfoService userInfoService;

	/**
	 * 分页获取所有的用户
	 * @return
	 */
	@ApiOperation(value = "分页获取所有的用户")
	@PostMapping("/queryPage")
	public Page<UserInfo> queryUserPage(@PageableDefault Pageable pageable){
		Page<UserInfo> userInfos = userInfoService.queryUserPage(pageable.getPageNumber(), pageable.getPageSize());
		return userInfos;
	}

	/**
	 * 添加或者修改用户
	 */
	@ApiOperation(value = "添加或者修改用户")
	@PostMapping("/saveOrUpdate")
    public	void saveOrUpdate(@RequestBody UserInfo userInfo){
		userInfoService.saveOrUpdate(userInfo);
	}

	/**
	 * 删除用户
	 */
	@ApiOperation(value = "删除用户")
	@DeleteMapping("/delete")
	public void deleteUserById(@RequestParam("id") Long id){
		userInfoService.deleteUserById(id);
	}

}
